import { Req, type Resp } from '@/utils/request'

// 获取用户列表
export function getUserList(page: {
  pageSize: number
  pageNum: number
}): Promise<Resp<PageInfo<User>>> {
  return Req.$get<PageInfo<User>>('/system/user/list', page)
}

// 添加用户
export function addUser(user: User): Promise<Resp<any>> {
  return Req.$post<any>('/system/user/add', user)
}

// 更新用户
export function updateUser(user: User): Promise<Resp<any>> {
  return Req.$put<any>('/system/user/update', user)
}

// 获取关联
export function getRelation(id: number): Promise<Resp<number[]>> {
  return Req.$get<number[]>('/system/user/getRelation', { id })
}

// 获取角色简要列表
export function getRoleConcise(): Promise<Resp<Role[]>> {
  return Req.$get<Role[]>('/system/user/getRoleConcise')
}

// 更新角色关联
export function updateRelation(userId: number, roleIds: number[]): Promise<Resp<any>> {
  return Req.$post<any>('/system/user/updateRelation', {}, { userId, roleIds })
}
